from langchain_core.documents import Document

# 构造文档
documents = [
    Document(
        page_content="狗是很好的伴侣，以忠诚和友善而闻名。",
        metadata={"source": "mammal-pets-doc"},
    ),
    Document(
        page_content="猫是独立的宠物，经常享受自己的空间。",
        metadata={"source": "mammal-pets-doc"},
    ),
    Document(
        page_content="金鱼是深受初学者欢迎的宠物，需要相对简单的护理。",
        metadata={"source": "fish-pets-doc"},
    ),
    Document(
        page_content="鹦鹉是一种聪明的鸟类，能够模仿人类的语言。",
        metadata={"source": "bird-pets-doc"},
    ),
    Document(
        page_content="兔子是群居动物，需要足够的空间来跳跃。",
        metadata={"source": "mammal-pets-doc"},
    ),
]



from langchain_chroma import Chroma
from langchain_community.embeddings import DashScopeEmbeddings

#实例化一个向量数据库=向量空间
vectorstore = Chroma.from_documents(
    documents,
    embedding=DashScopeEmbeddings(),
)

#相似度查询:返回相似的分数，分数越低相似度越高
result = vectorstore.similarity_search_with_score("猫")
print(result)